// pages/around_detail/around_detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail_title: '',
    location: null,
    amap:'',
    all: null,
    region: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.detail_title,options.amap,options.location)
    //获取地理位置
    let that = this
    that.setData({
      detail_title:options.detail_title,
      amap:options.amap,
      location:options.location
    })
    that.getAround()
  },
  getAround() {
    let that = this
    wx.request({
      url: 'https://restapi.amap.com/v3/place/around?',
      data: {
        key: '2b8e8119dc262a8e1af2f57d9a1552f3',
        location: that.data.location,
        types: that.data.amap
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log('中餐厅', res)
        that.setData({
          all: res.data.pois
        })
        console.log(that.data.all)
      }
    })
  },
  navigateBack(){
    wx.navigateBack({
      delta: 1
    })
  },
  // getAll() {
  //   let that = this
  //   let p = new Promise((a, b) => {
  //     wx.getLocation({
  //       type: 'wgs84',
  //       success(res) {
  //         a(res)
  //       }
  //     })
  //   })
  //   p.then((res) => {
  //     that.setData({
  //       location: res.longitude + ',' + res.latitude
  //     })
  //   }).then(() => {
  //     wx.request({
  //       url: 'https://restapi.amap.com/v3/geocode/regeo?',
  //       data: {
  //         key: '2b8e8119dc262a8e1af2f57d9a1552f3',
  //         location: that.data.location
  //       },
  //       header: {
  //         'content-type': 'application/json' // 默认值
  //       },
  //       success(res) {
  //         console.log('地理位置', res)
  //         let arr = res.data.regeocode.formatted_address
  //         that.setData({
  //           region: arr
  //         })
  //       }
  //     })
  //     that.getAround()
  //   })
  // },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})